﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using matrixdotnet.Common;

namespace Cinema
{
    public class Film : IFilm
    {
        private FilmUniqueKey _uniqueKey;
        private string _description;
        private PositiveValue<short> _duration;
        private string _imagePath;
        private DateTime? _discontinueDate;


        public Film(
            string name,
            string description,
            string director,
            string imagePath,
            PositiveValue<short> duration)
            : this(name, description, director, imagePath, duration, null)
        {
        }

        public Film(
            string name,
            string description,
            string director,
            string imagePath,
            PositiveValue<short> duration,
            DateTime? discontinueDate)
        {
            UniqueKey = new FilmUniqueKey(name, director);
            Description = description;
            ImagePath = imagePath;
            Duration = duration;
            DiscontinueDate = discontinueDate;
        }

        public FilmUniqueKey UniqueKey
        {
            get
            {
                return _uniqueKey;
            }
            protected set
            {
                _uniqueKey = value;
            }
        }

        public string Name
        {
            get
            {
                return UniqueKey.Name;
            }
            set
            {
                _uniqueKey.Name = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                CheckDescription(value);
                _description = value;
            }
        }

        public string Director
        {
            get
            {
                return UniqueKey.Director;
            }
            set
            {
                _uniqueKey.Director = value;
            }
        }

        public PositiveValue<short> Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }

        public string ImagePath
        {
            get
            {
                return _imagePath;
            }
            set
            {
                CheckImagePath(value);
                _imagePath = value;
            }
        }

        public DateTime? DiscontinueDate
        {
            get
            {
                return _discontinueDate;
            }
            set
            {
                _discontinueDate = value;
            }
        }

        public static void CheckDescription(string description)
        {
            if (string.IsNullOrEmpty(description))
                throw new ArgumentException("The film description can't be null or empty", "description");
        }
        public static void CheckImagePath(string imagePath)
        {
            if (string.IsNullOrEmpty(imagePath))
                throw new ArgumentException("The film imagePath can't be null or empty", "imagePath");
        }
    }
}
